06一个JAVA小程序 求解`````````

来源:百度知道 编辑:UC知道 时间:2024/06/24 16:43:28
6.编写应用程序,其中创建一个文本区,两个按钮,并将两个按钮添加到面
板中。对文本区和面板设置为2行1列的GridLayout布局。,给在文本区中显示你的名字,单击第二个按钮时,清除文本区中的内容。

建议你用SWT来编写,这会很方便~SWT是eclipse的一个API,负责处理界面设计。

怎么都是些基础的东西 自己学这解决吧

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import javax.swing.border.LineBorder;

public class Area extends javax.swing.JFrame {
private JTextArea name;
private JButton showname;
private JButton cleanname;
private JPanel panel;

/**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Area inst = new Area();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}

public Area() {
super();
i